import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { alternatives } from '..';
import { FileSchema } from '../../schema';

export class SaveFileValidator implements FileSchema {
  @ApiProperty({
    type: 'string',
    title: '文件名称',
    example: 'null',
    description: '文件名称',
    required: true,
  })
  @Rule(RuleType.string().required())
  fileName: string;

  @ApiProperty({
    type: 'string',
    title: '文件存储路径',
    example: 'null',
    description: '文件存储路径',
    required: true,
  })
  @Rule(RuleType.string().required())
  fileUrl: string;

  @ApiProperty({
    type: 'string',
    title: '文件媒体类型',
    example: 'null',
    description: '文件媒体类型',
    required: true,
  })
  @Rule(RuleType.string().required())
  mimeType: string;
}

export class EditFileValidator implements Partial<FileSchema> {
  @ApiProperty({
    type: 'string',
    title: '文件名称',
    example: 'null',
    description: '文件名称',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  fileName?: string;

  @ApiProperty({
    type: 'string',
    title: '文件存储路径',
    example: 'null',
    description: '文件存储路径',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  fileUrl?: string;

  @ApiProperty({
    type: 'string',
    title: '文件媒体类型',
    example: 'null',
    description: '文件媒体类型',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  mimeType?: string;
}
